	#e[Stage]
	#Title[Little Star Magic ver0.50]
	#Text[Little Star Magic ver0.50]
	#Player[.\player\Player.txt]
	#BackGround[User]
	#BackGround[Defalt]
	#ScriptVersion[2]

	script_stage_main
	{
		#include_function ".\txt/StageIniData.txt"

		#include_function ".\Settingtxt/StageEdit.txt"
		#include_function ".\Settingtxt/StageEdit2.txt"
		#include_function ".\Settingtxt/StageEdit3.txt"
		#include_function ".\Settingtxt/StageEdit4.txt"
		#include_function ".\Settingtxt/StageEdit5.txt"


ascent(i in 0..100)
{
	if(SetPlayerPosition[i]==[0,0])
	{
		SpellCardScScript[i]=csd~"Stage\Stage.txt";
	}
}

		task StageTask
		{
			yield;
			ShootFlagTask;

			MenuBackDraw;

		//	UpTimeCount;//NԌv
			PlayTimeCount;//vCԌv

			StageTitleDisplay;

			ForbidShot(false);
			ForbidBomb(false);

		}
	
		
		@Initialize()
		{

        LoadGraphic(imgShot);
        LoadGraphic(imgCircle);
        LoadGraphic(imgPlain);
        LoadGraphic(imgWater);
        LoadGraphic(imgWood);
        LoadGraphic(imgMagma);
        LoadGraphic(imgGoal);
        LoadGraphic(imgPlayer);
        LoadGraphic(imgAllow1);
        LoadGraphic(imgAllow2);
        LoadGraphic(imgAllow3);
        LoadGraphic(imgAllow4);
        LoadGraphic(imgBlock);
        LoadGraphic(imgFloor);

			CreateCommonDataArea(NsScore);
			LoadGraphic(imgBG);
			LoadGraphic(imgMenuEffect);
			LoadGraphic(imgLetter);
			LoadGraphic(imgChargeItem);
			LoadGraphic(imgMenuLetter);
			let isRep = IsReplay();
			if(isRep==false)
			{
				LoadCommonDataEx(NsScore,savePathstage);
			}
			else
			{
				LoadCommonDataFromReplayFile;
				StageState=Loading;
			}
			SetCommonData(NsIsReplay,isRep);
			SetCommonData(NsIsReplayJudgment,isRep);

			StageTask();
		}
	
		@MainLoop()
		{
			Object=SetObject[SpellSelect+SpellLevel*10];
			Graund=SetGraund[SpellSelect+SpellLevel*10];
			PlayerPosition=SetPlayerPosition[SpellSelect+SpellLevel*10];
			MagicStonePosition=SetMagicStonePosition[SpellSelect+SpellLevel*10];
			GoalPosition=SetGoalPosition[SpellSelect+SpellLevel*10];
			PedestalPosition=SetPedestalPosition[SpellSelect+SpellLevel*10];
			yield;

		}

		@DrawTopObject
		{
		/*	SetTexture(imgBG);
			SetGraphicScale(1.0,1.0);
			SetGraphicRect(0,0,384,448);
			if(StageState==Menu || StageState==Loading || StageState==Exit)
			{
				SetGraphicAngle(0, 0, 0);
				SetViewTo(0,0,0);
				DrawGraphic(GetCenterX, GetCenterY);
			}*/
			//DrawText(NumToString(GetCommonDataDefaultEx(NsScore,NsUpTime,0)/60),320,432,12,255);//NԂ̕\
			//DrawText(NumToStringNoComplete(GetCommonDataDefaultEx(NsScore,NsPlayTime,0)/60),320,452,12,255);//vCԂ̕\
			//DrawText(NumToStringNoComplete(GetCommonDataDefaultEx(NsScore,NsPlayTime,0)/6),320,432,12,255);//vCԂ̕\
			//DrawText(ToString(100),320,452,12,255);//vCԂ̕\
			//DrawText(StageState,120,432,12,255);//NԂ̕\
		//	DrawText(ppp,120,452,12,255);//vCԂ̕\
		//	DrawText(SetPlayerPosition[0],120,412,12,255);//NԂ̕\
			MenuDraw;
		}

		@Finalize()
		{
			if(GetCommonDataDefault(NsIsReplay,true) == false)
			{
				SaveCommonDataEx(NsScore,savePathstage);
			}
			ClearCommonDataEx(NsScore);
			DeleteCommonData(NsGetSpell);
			DeleteCommonData(NsDefeatFrame);
			DeleteCommonData(NsDefeatPosX);
			DeleteCommonData(NsDefeatPosY);
			DeleteCommonData(NsBossFrame);
			DeleteCommonData(NsIsReplay);
		}
		@BackGround {

			}

///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////Xe[WGtFNgAc@////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////
///////////Xe[WAgCł̐//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
let PhotoReload=true;
sub StageTitleDisplay//j[ʂ̕\ASecretSpellłĂяočċNĂB
{

if(GetCommonDataDefaultEx(NsScore,"MenuSpellNo",0)!=0)
{
	SpellSelect=GetCommonDataDefaultEx(NsScore,"MenuSpellNo",0);//savedata烁j[pSelectǂݍ
	SpellLevel=GetCommonDataDefaultEx(NsScore,"MenuSpellLevelNo",0);//savedata烁j[pLevelǂݍ
}
if(GetCommonDataDefaultEx(NsScore,"SpellNo",0)==0 && GetCommonData(NsIsReplayJudgment) == false)
{
if(MenuState==Menu)
{
PlayMusic(TitleBGM[0]);
}
SetCommonData("DoubleSpoilerStageMenu",true);

	if(MenuState==Menu)
	{
	DisPlayPlayer;
	DisPlayMagicStone;
	DisPlayGoal;
	DisPlayPedestal;
	GraundDraw;
	StageObject;
	}

	loop
	{
		alternative(StageState)	
		case(Menu)
		{
			TASK_MENU;
		}
		case(Exit)
		{
			StageState=Loading;
			SetCommonDataEx(NsScore,"SpellNo",SpellSelect);
			SetCommonDataEx(NsScore,"SpellLevelNo",SpellLevel);
			SetCommonDataEx(NsScore,"MenuSpellNo",0);
			SetCommonDataEx(NsScore,"MenuSpellLevelNo",0);

			SetCommonDataEx(NsScore,"Graund",Graund);
			SetCommonDataEx(NsScore,"Object",Object);
			SetCommonDataEx(NsScore,"PlayerPosition",PlayerPosition);
			SetCommonDataEx(NsScore,"MagicStonePosition",MagicStonePosition);
			SetCommonDataEx(NsScore,"GoalPosition",GoalPosition);
			SetCommonDataEx(NsScore,"PedestalPosition",PedestalPosition);

			SaveCommonDataEx(NsScore,savePath);//Select&Levelۑ
			wait(5);
			SetCommonData("DoubleSpoilerStageMenu",false);
			Retry;
			break;
		 }
		others{}
	yield;
	}
}

else
{

StageState=Start;
if(GetCommonData(NsIsReplayJudgment) == false)
{
	Graund=GetCommonDataDefaultEx(NsScore,"Graund",1);
	SetCommonDataEx(NsScore,"Graund",Graund);
	SetCommonData("Graund",Graund);
	Object=GetCommonDataDefaultEx(NsScore,"Object",1);
	SetCommonDataEx(NsScore,"Object",Object);
	SetCommonData("Object",Object);
	PlayerPosition=GetCommonDataDefaultEx(NsScore,"PlayerPosition",1);
	SetCommonDataEx(NsScore,"PlayerPosition",PlayerPosition);
	SetCommonData("PlayerPosition",PlayerPosition);
	MagicStonePosition=GetCommonDataDefaultEx(NsScore,"MagicStonePosition",1);
	SetCommonDataEx(NsScore,"MagicStonePosition",MagicStonePosition);
	SetCommonData("MagicStonePosition",MagicStonePosition);
	GoalPosition=GetCommonDataDefaultEx(NsScore,"GoalPosition",1);
	SetCommonDataEx(NsScore,"GoalPosition",GoalPosition);
	SetCommonData("GoalPosition",GoalPosition);
	PedestalPosition=GetCommonDataDefaultEx(NsScore,"PedestalPosition",1);
	SetCommonDataEx(NsScore,"PedestalPosition",PedestalPosition);
	SetCommonData("PedestalPosition",PedestalPosition);

	SpellSelect=GetCommonDataDefaultEx(NsScore,"SpellNo",1);
	SpellLevel=GetCommonDataDefaultEx(NsScore,"SpellLevelNo",1);
	SetCommonDataEx(NsScore,"SpellNo",SpellSelect);
	SetCommonData("SpellNo",SpellSelect);
	SetCommonDataEx(NsScore,"SpellLevelNo",SpellLevel);
	SetCommonData("SpellLevelNo",SpellLevel);
	SaveCommonDataInReplayFile;
	SetCommonDataEx(NsScore,"SpellNo",0);
	SetCommonDataEx(NsScore,"SpellLevelNo",0);
}

else
{
	SpellSelect=GetCommonDataDefault("SpellNo",2);
	SpellLevel=GetCommonDataDefault("SpellLevelNo",2);
	SetCommonData(NsIsReplayJudgment,false);
}
}

DisPlayScore(SpellSelect);//XRA\

	ForbidShot(false);
	PlayMusic(SceneBGM[SpellSelect+SpellLevel*10]);
	//CreateEnemyFromFile(SpellCardScScript[SpellSelect+SpellLevel*10],GetCenterX,GetClipMinY,2,0,0);
	CreateEnemyFromFile(csd~"Stage\Stage.txt",GetCenterX,GetClipMinY,2,0,0);
	wait(5);
	while(GetCommonDataDefault("StagePlaying",false)==true || StageState==Menu)
	{
		yield;
	}
	if(GetCommonDataDefault("StageClear",false)==true)
	{
	DeleteMusic(SceneBGM[SpellSelect+SpellLevel*10]);
	PlayMusic(TitleBGM[1]);
	wait(120);
	}
	wait(60);
	EndSpellMenu;
}

task EndSpellMenu
{
	Select=3000;
	StageState=Menu;
	MenuState=MenuDifficult;
	endbunka;
	PhotoReload=false;
	StageTitleDisplay;
}

task endbunka
{
	while(MenuState==MenuDifficult){yield;}
	StageState=Loading;
	SetCommonDataEx(NsScore,"MenuSpellNo",SpellSelect);
	SetCommonDataEx(NsScore,"MenuSpellLevelNo",SpellLevel);
	SaveCommonDataEx(NsScore,savePath);
	yield;
	Retry;
}
////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////ACe////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////
//////////////////ԌvA񐔋L^/////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
		task UpTimeCount//NԂ̌v
		{
			let UpTime=GetCommonDataDefaultEx(NsScore,NsUpTime,0);
			loop
			{
				UpTime++;
				SetCommonDataEx(NsScore,NsUpTime,UpTime);
				yield;
			}
		}

		task PlayTimeCount//vCԂ̌v
		{
			let PlayTime=GetCommonDataDefaultEx(NsScore,NsPlayTime,0);
			loop
			{
				if(StageState!=Menu)
				{
				PlayTime++;
				}
				SetCommonDataEx(NsScore,NsPlayTime,PlayTime);
				yield;
			}
		}
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////XRA\Aʐ^̋L^//////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
task DisPlayScore(let SpellNo)//nCXRAĂяoAnCXRAƌXRA\
{
let EachHiScore=0;

while(GetCommonDataDefault("StagePlaying",false)==false){yield;}
	CreateScore(GetCommonDataDefaultEx(NsScore,Player1Hiscore[SpellNo+SpellLevel*10],0),SpellNo+SpellLevel*10);
}

function CreateScore(let EachHiScore,SpellNo)//
{
while(GetCommonDataDefault("StagePlaying",false)==true)
{
	ScoreNumber1+=GetScore;
	AddScore(-GetScore);

//	DisPlayScoreNumber(GetClipMinX+80,GetClipMinY+20,EachHiScore,ScoreNumber2);//nCXRA
//	DisPlayScoreNumber(GetClipMaxX-10,GetClipMinY+20,ScoreNumber1,ScoreNumber2);//XRA

yield;
}
/*
	let Number=GetCommonDataDefaultEx(NsScore,Player1AllPhoto[SpellNo],0);
	SetCommonDataEx(NsScore,Player1Challenge[SpellNo],GetCommonDataDefaultEx(NsScore,Player1Challenge[SpellNo],0)+1);//񐔂𑝂₷
	SetCommonDataEx(NsScore,Player1AllPhoto[SpellNo],Number+GetCommonDataDefault("AllPhoto",0));//OԂɖ𑝂₵ĕۑ
		if(GetCommonDataDefaultEx(NsScore,Player1Hiscore[SpellNo],0)==0)
		{
			SetCommonDataEx(NsScore,Player1FirstClearChallenge[SpellNo],GetCommonDataDefaultEx(NsScore,Player1FirstClearChallenge[SpellNo],0)+1);//񐔂𑝂₷
			SetCommonDataEx(NsScore,Player1FirstClearPhoto[SpellNo],GetCommonDataDefaultEx(NsScore,Player1FirstClearPhoto[SpellNo],0)+GetCommonDataDefault("AllPhoto",0));
		}
*/
if(EachHiScore>=ScoreNumber1 && GetCommonDataDefault("StageClear",false)==true)
{
	SetCommonDataEx(NsScore,Player1Hiscore[SpellNo],ScoreNumber1);//OԂɃnCXRAۑ
}
else if(EachHiScore==0 && GetCommonDataDefault("StageClear",false)==true)
{
	SetCommonDataEx(NsScore,Player1Hiscore[SpellNo],ScoreNumber1);//OԂɃnCXRAۑ
}


	AddScore(ScoreNumber1);
	AddScore(SpellLevel*100000000+SpellSelect*10000000);


loop
{

//	DisPlayScoreNumber(GetClipMinX+80,GetClipMinY+20,EachHiScore,ScoreNumber2);
//	DisPlayScoreNumber(GetClipMaxX-10,GetClipMinY+20,ScoreNumber1,ScoreNumber2);
	yield;
}

}


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////CN[h////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
#include_function ".\settingtxt/LevelNorma.txt"
#include_function ".\settingtxt/BGM.txt"
#include_function ".\txt/MENU.txt"
#include_function ".\txt/MENUDRAW.txt"
#include_function ".\txt/DrawMenuLetterData.txt"
#include_function ".\txt/Display.txt"
}